package com.ttc.mBackupK16;


import com.ttc.mBackupK16.BackupContacts.ContactsBackup;
import com.ttc.mBackupK16.BackupPhotos.PhotosBackup;
import com.ttc.mBackupK16.BackupSMS.SMSBackup;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MBackupK16Activity extends Activity implements OnClickListener{
	
	private final static int BACKUP = 0;
	private final static int RESTORE = 1;
	private final static int MANAGE = 2;
	private final static int SCHEDULE = 3;
	
	public ObjectBackup myObject = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btnBackup, btnRestore, btnManage, btnSchedule;
        
        btnBackup = (Button)findViewById(R.id.btnBackup);
        btnRestore = (Button)findViewById(R.id.btnRestore);
        btnManage = (Button)findViewById(R.id.btnManage);
        btnSchedule = (Button)findViewById(R.id.btnSchedule);
        
        btnBackup.setOnClickListener(this);
        btnRestore.setOnClickListener(this);
        btnManage.setOnClickListener(this);
        btnSchedule.setOnClickListener(this);
    }
    
    @Override
    public void onClick(View v) {
    	// TODO Auto-generated method stub
    	switch (v.getId()) {
		case R.id.btnBackup:
			showObjectTypeDialog(BACKUP, "Backup ?", R.drawable.ic_backup);
	    	break;
		case R.id.btnRestore:
			showObjectTypeDialog(RESTORE, "Restore ?", R.drawable.ic_restore);
	    	break;
		case R.id.btnManage:
			showObjectTypeDialog(MANAGE, "Manage ?", R.drawable.ic_manage);
	    	break;
		case R.id.btnSchedule:
			showObjectTypeDialog(SCHEDULE, "Schedule ?", R.drawable.ic_schedule);
	    	break;
	    	
		default:
			break;
		}
    	
    }
    
    private void callMenuType(int iType){
    	if(myObject == null) return;
    	switch (iType) {
		case BACKUP:
			myObject.backup(this);
			break;
		case RESTORE:
			myObject.restore(this);
			break;
		case MANAGE:
			myObject.manage(this);
			break;
		case SCHEDULE:
			myObject.schedule(this);
			break;

		default:
			break;
		}
    }
    
    private void showObjectTypeDialog(final int iType, String strTitle, int iIDIcon){
    	AlertDialog.Builder builder =  new AlertDialog.Builder(this);
		builder.setTitle(strTitle);
		builder.setIcon(iIDIcon);
		builder.setItems(R.array.objects, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				switch (which) {
				case 0:
					myObject = new ContactsBackup();
					break;
				case 1:
					myObject = new SMSBackup();
					break;
				case 2:
					myObject = new PhotosBackup();
					break;

				default:
					myObject = null;
					break;
				}
				callMenuType(iType);
				dialog.dismiss();
			}
		});
		builder.show();
    }
}